package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dbclass.NoticiaDAO;
import dbclass.NoticiaJDBC;

import beans.Noticia;

/**
 * Servlet implementation class NoticiasComet
 */
public class NoticiasComet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String delimitador = "delimitador";
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NoticiasComet() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		//Verifica login

	
		NoticiaDAO noticiaDAO = new NoticiaJDBC();

		java.util.List<Noticia> noticias = null;  	

		
		try {  
			noticias = noticiaDAO.findAll();  
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();   
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace(); 
		}
		session.setAttribute("noticias", noticias);  
		
		String url="/NoticiaComet.jsp";   
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher(url);
		rd.forward(request, response);  
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
